<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>构造函数继承</title>
</head>
<body>

<script type="text/javascript">

  // 构造函数继承
  function SuperClass (id) {
    const name = 'javascript'
    this.books = ['javascript', 'typescript', 'css']
  }

  // 声明父类原型的方法
  SuperClass.prototype.showBooks = function () {
    console.log(this.books)
  }

  // 声明子类
  function SubClass (id) {
    SuperClass.call(this, id)
  }

  // 并不会继承父类原型对象的方法
  console.log(SubClass.prototype)

  // 创建第一个子类实例
  const subClass1 = new SubClass(10)
  const subClass2 = new SubClass(11)

  console.log(subClass1.books)
  console.log(subClass2.id) // id访问不到
  console.log(subClass1.name) // name访问不到
  // subClass2.showBooks()

</script>

</body>
</html>
